﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessObjects.BO_GetObjects;

public partial class Controls_ucPinkTab : System.Web.UI.UserControl
{
    string module_id;

    public string Module_id
    {
        get { return module_id; }
        set { module_id = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadData();
        }
    }

    protected void loadData()
    {
        DataTable objDT = BO_Articles.SelectByModuleCategory(Convert.ToInt32(module_id), 1, 3, 2/*, 1/*Convert.ToInt32(module_id)*/);
        if (objDT.Rows.Count > 0)
        {
            rptNews.DataSource = objDT;
            rptNews.DataBind();
        }
        objDT = BO_Articles.SelectByModuleCategory(Convert.ToInt32(module_id), 1, 3, 6);
        if (objDT.Rows.Count > 0)
        {
            rptWind.DataSource = objDT;
            rptWind.DataBind();
        }
        objDT = BO_Articles.SelectByModuleCategory(Convert.ToInt32(module_id), 1, 3, 7);
        if (objDT.Rows.Count > 0)
        {
            rptService.DataSource = objDT;
            rptService.DataBind();
        }
    }

    protected DataTable getRelativePost(string id, int from, int max)
    {
        DataTable objDT = BO_Articles.SelectWithTags(Convert.ToInt32(id), max);
        if (from > 0)
        {
            int count = Convert.ToInt32(from);
            for (int i = 0; i < count; i++)
            {
                if (count > objDT.Rows.Count)
                {
                    break;
                }
                else
                {
                    objDT.Rows.RemoveAt(0);
                }
            }
        }
        return objDT;
    }

    protected string getEvent(int index)
    {
        if (index % 2 != 0)
        {
            return "";
        }
        else
        {
            return "even";
        }
    }

    protected string getPrice(string unit_price)
    {
        decimal price = Convert.ToDecimal(unit_price);
        string strPrice = price.ToString();
        if (price > 1000000)
        {
            int dTemp = 0;
            dTemp += Convert.ToInt32(price / 1000000);
            strPrice = dTemp + " Triệu ";
            if (price - Convert.ToDecimal(dTemp * 1000000) > 0)
            {
                strPrice += (price - Convert.ToDecimal(dTemp * 1000000)) / 1000;
            }
        }
        return strPrice;
    }
}